<!--
 * @Author: Shususumu
 * @Date: 2020-10-15 15:57:45
 * @LastEditTime: 2020-10-20 10:27:32
 * @FilePath: \campusPTjobs\src\views\comment\index.vue
-->
<template>
  <div id="comment">
    <!-- 表格 -->
    <template>
      <el-table :data="commentList" stripe style="width: 100%">
        <el-table-column fixed prop="id" label="编号" width="80">
        </el-table-column>
        <el-table-column fixed prop="content" label="评论内容">
        </el-table-column>
        <el-table-column prop="commentTime" label="评论时间" width="200">
        </el-table-column>
        <el-table-column prop="orderId" label="产品ID" width="150">
        </el-table-column>
        <el-table-column prop="status" label="状态" width="160">
        </el-table-column>
        <el-table-column fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button @click="dlt(scope.row)" type="text" size="small"
              >删除</el-button
            >
            <el-button
              @click="Examine(scope.row.id)"
              type="text"
              size="small"
              :disabled="scope.row.status == '审核通过' ? true : false"
              >审核通过</el-button
            >
            <el-button
              @click="reExamine(scope.row.id)"
              type="text"
              size="small"
              :disabled="scope.row.status == '审核不通过' ? true : false"
              >审核不通过</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </template>
    <!-- 分页 -->
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[6, 8, 10, 12]"
      :page-size="6"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>
<script>
import qs from "querystring";
export default {
  data() {
    return {
      comments: [],
      currentPage: 1,
      total: 1,
      pageSize: 6,
    };
  },
  computed: {
    commentList() {
      this.comments.forEach((item) => {
        item.commentTime = new Date(item.commentTime).toLocaleString();
      });
      return this.comments;
    },
  },
  methods: {
    // 全局封装分页查询
    findquery() {
      var pageobj = { page: this.currentPage - 1, pageSize: this.pageSize };
      pageobj = qs.stringify(pageobj);
      this.$axios.post("/comment/query", pageobj).then((res) => {
        // console.log(res);
        this.comments = res.data.data.list;
        this.total = res.data.data.total;
      });
    },

    //删除
    dlt(row) {
      var id = row.id;
      this.$confirm("此操作将永久删除该产品, 是否继续?", "删除提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios
            .get("comment/deleteById", { params: { id } })
            .then((res) => {
              // console.log(res.data);
              if (res.data.status == 200) {
                this.$message({
                  type: "success",
                  message: res.data.message,
                });
                this.findquery();
              } else {
                this.$message({
                  type: "error",
                  message: "删除失败,绑定了其他数据",
                });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //审核功能
    Examine(id) {
      var commentid = id;
      this.$axios
        .get("/comment/commentExamine", { params: { commentid } })
        .then((res) => {
          this.findquery();
        });
    },
    reExamine(id) {
      var commentid = id;
      this.$axios
        .get("/comment/commentRefuseExamine", { params: { commentid } })
        .then((res) => {
          this.findquery();
        });
    },
    //分页功能
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.findquery();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.findquery();
    },
  },
  created() {
    this.findquery();
  },
};
</script>
<style lang="scss" scoped>
#comment {
  margin: 18px;
}
.el-input {
  width: 200px;
  margin-left: 20px;
}
</style>    